package com.navinfo.platform.producer;

import com.alibaba.fastjson.JSON;
import com.navinfo.opentsp.platform.location.protocol.common.RealTimeDataPb;
import com.navinfo.platform.bean.IncidentAlermData;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.common.serialization.ByteArraySerializer;
import org.apache.kafka.common.serialization.StringSerializer;

import java.util.Properties;

/**
 * Created by chen on 2019/7/23.
 */
public class Producer_driving {
    public static String topic = "incidentAlermPB";

    public static void main(String[] args) throws InterruptedException {
        Properties p = new Properties();
        p.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "platform-010-030-050-121:9092");
        p.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
        p.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
        KafkaProducer<String,String> kafkaProducer = new KafkaProducer(p);

        try {
            long time = 1566061200000L;
            IncidentAlermData incidentAlermData = new IncidentAlermData();
            incidentAlermData.setTid(13800138009L);
            incidentAlermData.setTripId(123);
            incidentAlermData.setTripDay("20200415");
            incidentAlermData.setRouteStartTime(1566061204L);
            incidentAlermData.setRouteStartLc(123);
            incidentAlermData.setRouteStartLatitude(110000000);
            incidentAlermData.setRouteStartLongitude(22000000);
            incidentAlermData.setRouteStartHeight(100);
            incidentAlermData.setRouteStartDirection(100);
            incidentAlermData.setRouteStartMileage(101);
            incidentAlermData.setRouteStartFuel(102);
            incidentAlermData.setRouteEndTime(1566071200L);
            incidentAlermData.setRouteEndLc(234);
            incidentAlermData.setRouteEndLatitude(110000000);
            incidentAlermData.setRouteEndLongitude(22000000);
            incidentAlermData.setRouteEndHeight(100);
            incidentAlermData.setRouteEndDirection(100);
            incidentAlermData.setRouteEndMileage(201);
            incidentAlermData.setRouteEndFuel(203);
            incidentAlermData.setRouteIntegralMileage(105);
            incidentAlermData.setRouteIntegralFuel(106);
            incidentAlermData.setRouteIntegralDuration(107);
            incidentAlermData.setTripMileage(108);
            incidentAlermData.setTripFuel(109);
            incidentAlermData.setTripDuration(110);
            incidentAlermData.setTripPower(111);
            incidentAlermData.setPreciseFlag(0);
            incidentAlermData.setCrossDayFlag(0);
            incidentAlermData.setSharpTurningNumber(117);
            incidentAlermData.setNightRunningNumber(118);
            incidentAlermData.setEmergencyStopNumber(119);
            incidentAlermData.setFlameoutCoastNumber(120);
            incidentAlermData.setColdRunningDuration(121);
            incidentAlermData.setColdRunningFuel(122);
            incidentAlermData.setColdRunningDuration(123);
            incidentAlermData.setColdRunningNumber(124);
            incidentAlermData.setNoEcoDrivingMileage(125);
            incidentAlermData.setNoEcoDrivingFuel(126);
            incidentAlermData.setNoEcoDrivingDuration(127);
            incidentAlermData.setNoEcoDrivingNumber(128);
            incidentAlermData.setNoEcoDrivingProportion(129);
            incidentAlermData.setFatigueDrivingNumber(130);
            incidentAlermData.setFatigueDrivingDuration(131);


            for(int i=0;i<5000;i++) {

                ProducerRecord<String,String> record = new ProducerRecord<String, String>(topic, JSON.toJSONString(incidentAlermData));
                kafkaProducer.send(record);
                System.out.println("消息发送成功:" + i);
                Thread.sleep(5);
            }
        }
        catch (Exception e){
            e.printStackTrace();
        }
        finally {
            kafkaProducer.close();
        }

    }
}
